/*----------- start Tile -----------*/
var TILE_TYPE_4_4 = [4, 4];
var TILE_TYPE_5_4 = [5, 4];
var TILE_TYPE_6_4 = [6, 4];
var TILE_TYPE_7_4 = [7, 4];
var TILE_TYPE_8_4 = [8, 4];
var TILE_TYPE_9_4 = [9, 4];
var TILE_TYPE_10_4 = [10, 4];
var TILE_TYPE_11_4 = [11, 4];

var TILE_TYPE_3_5 = [3, 5];
var TILE_TYPE_4_5 = [4, 5];
var TILE_TYPE_5_5 = [5, 5];
var TILE_TYPE_8_5 = [8, 5];
var TILE_TYPE_9_5 = [9, 5];
var TILE_TYPE_10_5 = [10, 5];
var TILE_TYPE_11_5 = [11, 5];
var TILE_TYPE_12_5 = [12, 5];

var TILE_TYPE_1_6 = [1, 6];
var TILE_TYPE_2_6 = [2, 6];
var TILE_TYPE_3_6 = [3, 6];
var TILE_TYPE_4_6 = [4, 6];
var TILE_TYPE_5_6 = [5, 6];
var TILE_TYPE_6_6 = [6, 6];
var TILE_TYPE_7_6 = [7, 6];
var TILE_TYPE_8_6 = [8, 6];
var TILE_TYPE_9_6 = [9, 6];
var TILE_TYPE_10_6 = [10, 6];
var TILE_TYPE_11_6 = [11, 6];
var TILE_TYPE_12_6 = [12, 6];

var TILE_TYPE_1_7 = [1, 7];
var TILE_TYPE_2_7 = [2, 7];
var TILE_TYPE_3_7 = [3, 7];
var TILE_TYPE_4_7 = [4, 7];
var TILE_TYPE_5_7 = [5, 7];
var TILE_TYPE_6_7 = [6, 7];
var TILE_TYPE_7_7 = [7, 7];
var TILE_TYPE_8_7 = [8, 7];
var TILE_TYPE_9_7 = [9, 7];
var TILE_TYPE_10_7 = [10, 7];
var TILE_TYPE_11_7 = [11, 7];

var tilesInit = function(){
    var index = 0;
    for (var i = 1; i < 13; i++) {
        for (var j = 1; j < 13; j++) {
            if (window['TILE_TYPE_' + j + '_' + i]) {
                window['TILE_TYPE_' + index++] = window['TILE_TYPE_' + j + '_' + i];
            }
        }
    } 
}();

function Tile(tileType, x, y, collisionManager) {
    this.collisionManager = collisionManager;
    this.x = x;
    this.y = y;
    this.halfWidth = 15;
    this.halfHeight = 15;
    this.x1 = this.x - this.halfWidth;
    this.x2 = this.x + this.halfWidth;
    this.y1 = this.y - this.halfHeight
    this.y2 = this.y + this.halfHeight
    this.dx = 0;
    this.dy = 0;
    this.remove = false;
    this.visible = true;
    this.tileType = tileType;
    this.sprite = new ImageSprite(IMAGE, {
        cellWidth: 32,
        cellHeight: 32,
        gridSpace: 1,
        x: tileType[0],
        y: tileType[1],
        offsetX: 16,
        offsetY: 16
    });
    this.collisionManager.objects.push(this);
}

Tile.prototype.update = function() {
    };

Tile.prototype.render = function(context) {
    if (this.visible) {
        this.sprite.x = this.x;
        this.sprite.y = this.y;
        this.sprite.render(context);
    }
};
/*----------- end Tile -----------*/